#include "timer.h"

/**
 * 01.03.12 - Steven Hartin - Original file creation
 */

CTimer::CTimer() : m_dTime(0.0)
{
    /**
     * Constructor, ensure that the time is intialised to the current system
     * time. If no value is passed, we can assume that the time should take
     * the default system time.
     */
    m_dTime = timeGetTime() / TIME_PRECISION;
}

CTimer::CTimer(double dTime) : m_dTime(dTime)
{
    /**
     * Conversion constructor, convert from a double time to a CTimer object.
     *
     * @param double dTime The current time represented as a double.
     */
}

const double CTimer::get_time() const
{
    /**
     * @return double The current time as a double, ever incrementing value.
     */
    return m_dTime;
}

void CTimer::setTime(double dTime)
{
    /**
     * Assigns a new time value to the object.
     *
     * @param double dTime The new value as a double to assign to the object
     */
    m_dTime = dTime;
}

void CTimer::setTime()
{
    /**
     * Assigns the current system time to the timer.
     */
    m_dTime = CTimer().get_time();
}

const double CTimer::getTimeDifference(const CTimer &other) const
{
    /**
     * Returns the time difference between two times. This will do 
     * othertime_seconds - thistime_seconds to obtain the time in seconds
     * that differentiate between the two.
     *
     * @param const CTimer &other The other timer to compare against
     * @return const double The amount of seconds that differ between the two
     *                      times
     */
    return other.get_time() - get_time();
}

const double CTimer::getTimeDifference(const double dOther) const
{
    /**
     * Returns the time difference between two times. Uses a double as a time
     * to compare against, which must be an ever incrementing number from
     * the FILETIME object.
     *
     * @param const double dOther The other time to compare against
     * @return const double The amount of time which differs between the two
     */
    return dOther - get_time();
}

const double CTimer::getTimeDifference() const
{
    /**
     * @return const double The amount of seconds which differs between the
     *                      current time and the time this timer represents.
     */
    //FILETIME stCurrentTime;
    //GetSystemTimeAsFileTime(&stCurrentTime);
    //return (stCurrentTime.dwLowDateTime / TIME_PRECISION) - get_time();
    return (CTimer() - get_time()).get_time();
}

CTimer CTimer::operator-(const CTimer &other) const
{
    /**
     * Performs a time difference between two times and returns a copy of the
     * new time value.
     *
     * @param const CTimer &other The other timer object
     * @return CTimer A copy of the result
     */
    CTimer newTimeDiff(*this);
    newTimeDiff.setTime(get_time() - other.get_time());
    return newTimeDiff;
}

CTimer CTimer::operator-(const double dOther) const
{
    /**
     * Performs a time difference between two times and returns a copy of the
     * new time value.
     *
     * @param const double The other timer object
     * @return CTimer A copy of the result
     */
    CTimer newTimeDiff(*this);
    newTimeDiff.setTime(get_time() - dOther);
    return newTimeDiff;
}

CTimer CTimer::operator+(const CTimer &other) const
{
    /**
     * Performs a time increment between two times and returns a copy of the
     * new time value.
     *
     * @param const CTimer &other The other timer object
     * @return CTimer A copy of the result
     */
    CTimer newTimeDiff(*this);
    newTimeDiff.setTime(get_time() + other.get_time());
    return newTimeDiff;
}

CTimer CTimer::operator+(const double dOther) const
{
    /**
     * Performs a time increments between two times and returns a copy of the
     * new time value.
     *
     * @param const double other The other timer object
     * @return CTimer A copy of the result
     */
    CTimer newTimeDiff(*this);
    newTimeDiff.setTime(get_time() + dOther);
    return newTimeDiff;
}

const CTimer & CTimer::operator-=(const CTimer &other)
{
    /**
     * Deducts a specfic time value from this object.
     *
     * @param CTimer &other The other time object.
     * @return const CTimer& A reference to this object to allow chain reference
     */
    setTime(get_time() - other.get_time());
    return *this;
}

const CTimer & CTimer::operator-=(const double dOther)
{
    /**
     * Deducts a specfic time value from this object.
     *
     * @param CTimer &other The other time object.
     * @return const CTimer& A reference to this object to allow chain reference
     */
    setTime(get_time() - dOther);
    return *this;
}

const CTimer & CTimer::operator+=(const CTimer &other)
{
    /**
     * Adds a specfic time value from this object.
     *
     * @param CTimer &other The other time object.
     * @return const CTimer& A reference to this object to allow chain reference
     */
    setTime(get_time() + other.get_time());
    return *this;
}

const CTimer & CTimer::operator+=(const double dOther)
{
    /**
     * Adds a specfic time value from this object.
     *
     * @param CTimer &other The other time object.
     * @return const CTimer& A reference to this object to allow chain reference
     */
    setTime(get_time() + dOther);
    return *this;
}